package indi.kane.simpleproject.controller;

import indi.kane.simpleproject.entity.Member;
import indi.kane.simpleproject.service.impl.MemberService;
import indi.kane.simpleproject.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: MemberController
 * @Author: kane
 * @Date: 2019-11-05 5:48 下午
 * @Description:
 */
@RestController
@RequestMapping("member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    @RequestMapping(value = "get", method = RequestMethod.POST)
    public ResultVo get(@RequestParam( value = "id") Integer id){
        Member member = memberService.selectByPrimaryKey(id);
        return ResultVo.success(member);
    }

    @RequestMapping("insert")
    public ResultVo insert(@RequestBody Member member){
        try {
            int result = memberService.insertSelective(member);
            if(result > 0){
                return ResultVo.success("ok");
            }
            return ResultVo.failed("failed");
        }
        catch (Exception ex){
            return ResultVo.failed_exception(ex.getMessage());
        }
    }
}